package com.sky.Protocol;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * Created by sun on 2017-06-11.
 */
public class MessageChannelHandler extends ChannelInitializer<SocketChannel> {

    private int readerIdleTime;

    public MessageChannelHandler(int readerIdleTime) {
        this.readerIdleTime = readerIdleTime;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //添加自定义解码工具
        socketChannel.pipeline()
                .addLast(new IdleStateHandler(readerIdleTime,0,0, TimeUnit.SECONDS))
                .addLast(new MessageEncoder())
                .addLast(new MessageDecoder(Integer.MAX_VALUE,0,4,0,0,false))
                .addLast(new MessageHandler());
    }
}
